using System;
using System.Collections.Generic;
using System.Text;

using Derm.Render;

namespace Derm.Scene
{
	/// <summary>
	/// 
	/// </summary>
	public class SceneGrid : RenderObjectBase
	{
		#region Constructors

		public SceneGrid(float width, float height)
		{
			// Vertex array
			VertexArrayObject gridArray = new VertexArrayObject();
			ArrayBufferObject<Vertex3f> gridBuffer = new ArrayBufferObject<Vertex3f>(BufferObject.Hint.StaticCpuDraw);

			uint gridBufferIndex = 0;
			uint xSubdiv = (uint) width, ySubdiv = (uint) height;

			gridBuffer.Define((xSubdiv / 10 + 1) * 2 + (ySubdiv / 10 + 1) * 2);

			for (float x = -xSubdiv / 2.0f; x < +xSubdiv / 2.0f; x += 10.0f) {
				gridBuffer[gridBufferIndex++] = new Vertex3f(x, -ySubdiv / 2.0f, 0.0f);
				gridBuffer[gridBufferIndex++] = new Vertex3f(x, +ySubdiv / 2.0f, 0.0f);
			}

			for (float y = -ySubdiv / 2.0f; y <= +ySubdiv / 2.0f; y += 10.0f) {
				gridBuffer[gridBufferIndex++] = new Vertex3f(-xSubdiv / 2.0f, y, 0.0f);
				gridBuffer[gridBufferIndex++] = new Vertex3f(+ySubdiv / 2.0f, y, 0.0f);
			}

			gridArray.SetArray(VertexArraySemantic.Position, gridBuffer);
			gridArray.SetElementArray(Primitive.Line);

			VertexArrays.AddVertexArray(gridArray);

			// Shader program
			RenderProgram = ShaderLibrary.CreateShaderProgram("StandardShader");
		}

		#endregion
	}
}
